package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.poi.StringUtils;
import com.bwie.pojo.THb;
import com.bwie.pojo.THy;
import com.bwie.service.THbService;
import com.bwie.mapper.THbMapper;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 28463
* @description 针对表【t_hb】的数据库操作Service实现
* @createDate 2025-06-17 13:22:00
*/
@Service
public class THbServiceImpl extends ServiceImpl<THbMapper, THb>
    implements THbService{

    @Autowired
    THbMapper tHbMapper;
    @Override
    public R listHB(PageInfoVo pageInfoVo) {
        Page<THb> tHyPage = new Page<>(pageInfoVo.getPageNum(), pageInfoVo.getPageSize());
        QueryWrapper<THb> wrapper = new QueryWrapper<>();
        if(pageInfoVo.getHbPrice()!=null){
            wrapper.lambda().eq(THb::getHbPrice,pageInfoVo.getMinValue());
        }
        if(pageInfoVo.getHbPrice()!=null){
            wrapper.lambda().eq(THb::getHbPrice,pageInfoVo.getMaxValue());
        }
        if(!StringUtils.isEmpty(pageInfoVo.getHbTime())){
            wrapper.lambda().like(THb::getHbTime,pageInfoVo.getHbTime());
        }

        Page<THb> tHyPage1 = tHbMapper.selectPage(tHyPage, wrapper);
        return R.OK(tHyPage1);
    }

    @Override
    public R addHB(THb tHb) {

        if(tHb.getHbZt().length()>32){
            return R.ERROR(500,"主题题内容不得超过32个字符");
        }
        if(tHb.getHbPrice()>300){
            return R.ERROR(500,"红包总金额不得超过300元");
        }
        if(tHb.getHbPrice()>268.90){
            return R.ERROR(500,"红包总金额不得超过当前账户余额");
        }
//        if(tHb.getHbInt()<0){
//            return R.ERROR(500,"红包个数必须大于0");
//        }
        tHbMapper.insert(tHb);
        return R.OK();
    }
}




